package demo1;

import static java.lang.Thread.sleep;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-09-09
 * Time: 23:50
 */
public class Test3 {

    public static int peakIndexInMountainArray(int[] arr) {
        int left = 0, right = arr.length - 1;
        while(left < right){
            int mid = left + (right - left + 1) / 2;
            if(arr[mid] > arr[mid - 1]){
                left = mid;
            }
            if(arr[mid] < arr[mid - 1]){
                right = mid - 1;
            }
        }
        return left;
    }

    public static int findMin(int[] nums) {
        int len = nums.length - 1;
        int left = 0, right = len, count = 0;
        while(left < right){
            int mid = left + (right - left) / 2;
            if(nums[mid] >= nums[0]){
                left = mid + 1;
            }else{
                count = 1;
                right = mid;
            }
        }
        if(count == 0){
            if (nums[0] < nums[len]){
                return nums[0];
            }
        }
        return nums[left];
    }



    public static void main(String[] args) {
        int[] arr = {4,5,6,7,0,1,2};
        //peakIndexInMountainArray(arr);
        findMin(arr);
    }

//    public static int n = 0;
//    public static void main(String[] args) throws InterruptedException {
//        Thread thread = new Thread(() -> {
//            while (n != 0){
//                ;
//            }
//        });
//        sleep(1000);
//        n = 0;
//    }

//    public static void main(String[] args) throws InterruptedException {
//        Thread thread = new Thread(() -> {
//            while (!Thread.currentThread().isInterrupted()){
//                System.out.println("haha");
//            }
//        });
//        thread.start();
//        sleep(1000);
//        thread.interrupt();
//        thread.join();
//        thread.join(1000);
//        thread.join();
//    }

    //public static int n = 3;
//    public static void main(String[] args) {
//        boolean flag = true;
//        int n = 0;
//        Thread thread = new Thread(() -> {
//            while (n != 1){
//                ;
//            }
//            System.out.println("haha");
//        });
//        thread.start();
//        //n = 0;
//    }
}
